 ///
 /// @file    factory.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-17 11:33:57
 ///
 
#include <iostream>
using std::cout;
using std::endl;

class Product;


class Factory
{
public:
	Product * create()
	{
		return factoryMethod();
	}
	virtual Product * factoryMethod()=0;
};

class Product
{
public:
	Product(){}
	virtual ~Product(){}
};

class ProductA : public Product
{
public:
	ProductA()
	{
		cout << "ProductA()" << endl;
	}
	~ProductA()
	{
		cout << "~ProductA()" << endl;
	}
};

class ProductB : public Product
{
public:
	ProductB()
	{
		cout << "ProducB()" << endl;
	}

	~ProductB()
	{
		cout << "~ProductB()" << endl;
	}
};

class ConcreateFactoryA : public Factory
{
public:
	Product * factoryMethod()
	{
		return new ProductA;
	}
};

class ConcreateFactoryB : public Factory
{
public:
	Product * factoryMethod()
	{
		return new ProductB;
	}
};

int main(void)
{
	Factory * pConFactA = new ConcreateFactoryA;
	Product * pProductA = pConFactA->create();

	Factory * pConFactB = new ConcreateFactoryB;
	Product * pProductB = pConFactB->create();

	delete pProductA;
	delete pProductB;
	return 0;
}
